/**
 * $Id: Dialogs.js,v 1.46 2012-07-19 19:09:23 gaudenz Exp $
 * Copyright (c) 2006-2012, JGraph Ltd
 */
/**
 * Constructs a new dialog.
 */





function UpdateitemDialogTabel(pClass, pTitle, sendData, logData, actionData, ch, executablecontentval) {



    //  alert (actionData+logData+sendData);
    if (actionData == null && actionData == undefined && actionData == "undefined") {

        actionData = "";

    }

    if (logData == null && logData == undefined && logData == "undefined") {

        logData = "";

    }
    if (sendData == null && sendData == undefined && sendData == "undefined") {

        sendData = "";

    }

    for (var i = 0; i < 6; i++) {
        if (sendData[i] == null && sendData[i] == undefined && sendData[i] == "undefined") {

            sendData[i] = "";

        }

        if (logData[i] == null && logData[i] == undefined && logData[i] == "undefined") {

            logData[i] = "";

        }
        if (actionData[i] == null && actionData[i] == undefined && actionData[i] == "undefined") {

            actionData[i] = "";
        }


    }


    var table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');

    row = document.createElement('tr');
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, pTitle + ':');
    row.appendChild(td);







    td = createIntput(ch, pTitle + "val", '', "checkBox");
    row.appendChild(td);
    tbody.appendChild(row);



    row = document.createElement('tr');
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Executablecontent:');


    td.setAttribute('class', 'subtitle');
    row.appendChild(td);

    td = document.createElement('td');
    td.style.fontSize = '10pt';


    var myinput = document.createElement('select');

    myinput.setAttribute('class', pClass + 'executablecontentval');
    myinput.setAttribute('style', 'width:100px;');



    myinput.onchange = function() {



        //  alert ("."+pClass+$("."+pClass+"executablecontentval").val());
        $("." + pClass + "selectDivs").hide();
        $("." + pClass + $("." + pClass + "executablecontentval").val()).show();
    }

    alert(executablecontentval);

    var sendoption = document.createElement('option');
    mxUtils.write(sendoption, 'Send');
    myinput.appendChild(sendoption);


    if (executablecontentval == 'Send') {
        sendoption.setAttribute('selected', 'selected');



    }


    var logoption = document.createElement('option');
    logoption.setAttribute('value', 'Log');
    mxUtils.write(logoption, 'Log');
    myinput.appendChild(logoption);


    if (executablecontentval == 'Log') {



        logoption.setAttribute('selected', 'selected');





    }



    td.appendChild(myinput);
    row.appendChild(td);


    tbody.appendChild(row);
    /////////////////////////////////////////////////////////////////////////////////////////////// log//  value="label__expr__level;


    row = document.createElement('tr');
    row.setAttribute('class', pClass + 'selectDivs ' + pClass + 'Log');

    if (executablecontentval != 'Log') {
        row.setAttribute('style', 'display:none');

    }


    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Label:');
    row.appendChild(td);



    td = createIntput(logData[0], pClass + "Log_label", 'width:100px');
    row.appendChild(td);




    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Expr:');
    row.appendChild(td);


    td = createIntput(logData[1], pClass + "Log_exprval", 'width:100px');
    row.appendChild(td);


    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Level:');
    row.appendChild(td);
    td = document.createElement('td');
    td.style.fontSize = '10pt';


    td = createIntput(logData[2], pClass + "log_leve", 'width:100px');
    row.appendChild(td);
    tbody.appendChild(row);

    ///////////////////////////////////////////////////////////////

    row = document.createElement('tr');
    row.setAttribute('class', pClass + 'selectDivs ' + pClass + 'Send');

    if (executablecontentval == 'Log') {

        row.setAttribute('style', 'display:none');
    }


    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Event:');
    row.appendChild(td);

    td = document.createElement('td');
    td.style.fontSize = '10pt';
    myinput = document.createElement('input');
    myinput.setAttribute('class', 'send_event');
    myinput.setAttribute('style', 'width:100px;');
    td.appendChild(myinput);



    // send// value="event__target__targettype__namelist__delay__sendid__hints;"




    td = createIntput(sendData[0], pClass + "send_event", 'width:100px');
    row.appendChild(td);


    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Target:');


    row.appendChild(td);
    td = createIntput(sendData[1], pClass + "send_target", 'width:100px');
    row.appendChild(td);


    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Target Type:');
    row.appendChild(td);

    td = createIntput(sendData[2], pClass + "send_TaregetType", 'width:100px');
    row.appendChild(td);
    tbody.appendChild(row);


    //////////////////////////////////////////////////////////////////////////////////

    row = document.createElement('tr');
    row.setAttribute('class', pClass + 'selectDivs ' + pClass + 'Send');
    if (executablecontentval == 'Log') {

        row.setAttribute('style', 'display:none');
    }
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Send Id:');

    row.appendChild(td);
    td = createIntput(sendData[5], pClass + "send_Sendid", 'width:100px');
    row.appendChild(td);



    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Delay:');
    row.appendChild(td);


    td = createIntput(sendData[4], pClass + "send_delay", 'width:100px');
    row.appendChild(td);


    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Name List:');


    row.appendChild(td);
    td = createIntput(sendData[3], pClass + "send_name_list", 'width:100px');
    row.appendChild(td);


    tbody.appendChild(row);


    //////////////////////////////////////////////////////////////////////////////////


    row = document.createElement('tr');

    row.setAttribute('class', pClass + 'selectDivs ' + pClass + 'Send');

    if (executablecontentval == 'Log') {

        row.setAttribute('style', 'display:none');
    }



    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Hints');

    row.appendChild(td);

    td = createIntput(sendData[6], pClass + "send_hints", 'width:100px');
    row.appendChild(td);

    tbody.appendChild(row);

    ///////////////////////////////////////////////////////////////////////////////
    row = document.createElement('tr');
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Action:');
    td.setAttribute('class', 'subtitle');
    row.appendChild(td);


    td = createSelect(actionData[0]
            , pClass + "data_action",
            "width:100px",
            ["vdb-error", 'vdb-create', 'vdb-deferred-create', 'vdb-update', 'vdb-deferred-update', 'vdb-delete', 'vdb-deferred-delete'],
            ["vdb-error", 'vdb-create', 'vdb-deferred-create', 'vdb-update', 'vdb-deferred-update', 'vdb-delete', 'vdb-deferred-delete']
            );




    row.appendChild(td);


    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Id:');
    row.appendChild(td);

    td = createIntput(actionData[1], pClass + "action_id", 'width:100px');
    row.appendChild(td);


    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Procedure:');
    row.appendChild(td);

    td = createIntput(actionData[2], pClass + "action_procedure", 'width:100px');
    row.appendChild(td);
    tbody.appendChild(row);

    ///////////////////////////////////////////////////////////////////////////////


    row = document.createElement('tr');
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'On-Error:');
    row.appendChild(td);



    td = createSelect(actionData[3], pClass + "On-Errorval", "width:100px",
            ["Continue", 'Roll-back'], ["Continue", 'Roll-back']);

    row.appendChild(td);
    tbody.appendChild(row);
    table.appendChild(tbody);

    return table;

/////////////////////////////////////////////////////////////////////////////onentery


}

function getValueData(myclass, type) {

    var returnData = "";
    var v = unescape($("." + myclass).val());
    var data = v.split(";");

    if (data[type] != null) {

        returnData = data[type].split("__");
    }
    return   returnData;

}

function UpdateItemDialog(editorUi, graph, cell)
{
    var div = document.createElement('div');

    div.appendChild(createItem("State Properties", "", "thtitle"));
    var divd1 = document.createElement('div');
    divd1.setAttribute('class', 'divt1');




    var table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');


    row = document.createElement('tr');
    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Item Name:');
    row.appendChild(td);


    td = createIntput(cell.getValue(), "itemName", 'width:100px;');
    row.appendChild(td);

    tbody.appendChild(row);
    table.appendChild(tbody);
    divd1.appendChild(table);


    var oldv = cell.getId() + "." + cell.getValue().replaceAll(" ", "_");

    var sendData = getValueData(oldv + "__Data.send", 1);

    var logData = getValueData(oldv + "__Data.log", 1);

    var actionData = getValueData(oldv + "__Data.action", 1);


    var onexitSendData = getValueData(oldv + "__Data.Onexit_send", 1);

    var onexitLogData = getValueData(oldv + "__Data.Onexit_log", 1);

    var onexitActionData = getValueData(oldv + "__Data.Onexit_action", 1);


    // var onexitActionData=getValueData(oldv +"__Data.Onexit_ch");




    divd1.appendChild(UpdateitemDialogTabel("", "Onentry", sendData, logData, actionData, $("." + oldv + "__Data.ch").val(), $("." + oldv + "__Data.executablecontentvalh").val()));

    divd1.appendChild(UpdateitemDialogTabel("Onexit_", "Onexit", onexitSendData, onexitLogData, onexitActionData, $("." + oldv + "__Data.Onexit_ch").val(), $("." + oldv + "__Data.Onexit_executablecontentvalh").val()));


    table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    tbody = document.createElement('tbody');

    tbody.appendChild(row);
    row = document.createElement('tr');
    td = document.createElement('td');

    td.style.fontSize = '10pt';
    mxUtils.write(td, 'Targetless Transititon:');
    row.appendChild(td);
    td = document.createElement('td');

    td.setAttribute('colspan', '4');
    td.style.fontSize = '10pt';
    var myinput = document.createElement('textarea');
    myinput.setAttribute('class', 'targetless_transititon');

    myinput.setAttribute('value', $("." + oldv + "__Data.targetless_transititon").val());



    myinput.setAttribute('style', 'width:200px;');
    td.appendChild(myinput);
    row.appendChild(td);
    tbody.appendChild(row);

    table.appendChild(tbody);
    divd1.appendChild(table);

    var my = mxUtils.button("Update", function()
    {


        var myname = $(".itemName").val();

        var v = myname.replaceAll(" ", "_");

        $(".itmedata ." + v + "." + cell.getId() + "__Data").remove();
        v = cell.getId() + " " + v;

        cell.setValue(myname);




        graph.refresh();


        var myadddata = "";

        if ($('.Onentryval').is(':checked')) {


            myadddata += returnInputField(v + "__Data   ch", "checked");


            var value = "Onentry;Onentry";
            myadddata += "\n" + returnInputField(v + "__Data Onentry", value);






            if ($(".executablecontentval").val() == "Send") {
                myadddata += returnInputField(v + "__Data   executablecontentvalh", "Send");


                value = "event__target__targettype__namelist__delay__sendid__hints;"



                        + $(".send_event").val() + "__" + $(".send_target").val() + "__" + $(".send_TaregetType").val()
                        + "__" + $(".send_name_list").val() + "__" + $(".send_delay").val() + "__" + $(".send_Sendid").val()
                        + "__" + $(".send_hints").val()
                        ;
                myadddata += "\n" + returnInputField(v + "__Data send", value);





            } else {

                myadddata += returnInputField(v + "__Data   executablecontentvalh", "Log");
                if ($(".Log_exprval").val() != "") {


                    value = "label__expr__level;" + $(".Log_label").val() + "__" + $(".Log_exprval").val() + "__" + $(".log_leve").val();
                    myadddata += "\n" + returnInputField(v + "__Data log", value);

                }

            }





            if ($(".action_id").val() != "") {

                value = "data_action__id__procedure__on-error;" + $(".data_action").val() + "__" + $(".action_id").val() + "__" + $(".action_procedure").val() + "__" + $(".On-Errorval").val();
                myadddata += "\n" + returnInputField(v + "__Data action", value);


            }
        }






        if ($('.Onexitval').is(':checked')) {

            myadddata += returnInputField(v + "__Data   Onexit_ch", "checked");

            if ($(".Onexit_executablecontentval").val() == "Send") {

                myadddata += returnInputField(v + "__Data   Onexit_executablecontentvalh", "Send");



                value = "event__target__targettype__namelist__delay__sendid__hints;"
                        + $(".Onexit_send_event").val() + "__" + $(".Onexit_send_target").val() + "__" + $(".Onexit_send_TaregetType").val()
                        + "__" + $(".Onexit_send_name_list").val() + "__" + $(".Onexit_send_delay").val() + "__" + $(".Onexit_send_Sendid").val()
                        + "__" + $(".Onexit_send_hints").val()
                        ;
                myadddata += "\n" + returnInputField(v + "__Data Onexit_send", value);





            } else {


                myadddata += returnInputField(v + "__Data   Onexit_executablecontentvalh", "Log");
                if ($(".Onexit_Log_exprval").val() != "") {




                    value = "label__expr__level;" + $(".Onexit_Log_label").val() + "__" + $(".Onexit_Log_exprval").val() + "__" + $(".Onexit_log_leve").val();
                    myadddata += "\n" + returnInputField(v + "__Data Onexit_log", value);

                }

            }





            if ($(".Onexit_action_id").val() != "") {

                value = "data_action__id__procedure__on-error;" + $(".Onexit_data_action").val() + "__" + $(".Onexit_action_id").val() + "__" + $(".Onexit_action_procedure").val() + "__" + $(".Onexit_On-Errorval").val();
                myadddata += "\n" + returnInputField(v + "__Data Onexit_action", value);


            }

        }



        value = $(".targetless_transititon").val();
        myadddata += returnInputField(v + "__Data   targetless_transititon", value);


        //alert (myadddata);

        $(".itmedata").append(myadddata);


        editorUi.hideDialog();

    })





    my.setAttribute('class', 'myupdate');



    div.appendChild(my);


    div.appendChild(divd1);


    this.container = div;
}


function updateitemsOperations(old) {

    for (var i = 0; i < old.length; i++) {

        if (old[i] != "" && old[i] != null) {

            var val = old[i];
            var text = "";
            if (val == "migrate-error-resolve") {
                text = "Migrate Error resolve";
            } else if (val == "migrate") {
                text = "Migrate";

            }
            else if (val == "synchronise-create") {
                text = "Sync Create";

            }
            else if (val == "synchronise-error-resolve") {
                text = "Sync Error resolve";

            }
            else if (val == "synchronise-update") {
                text = "Sync Update";

            }
            else if (val == "user-event") {
                text = "User Event";

            }
            else if (val == "deferred-response") {
                text = "Deferred Response";

            }
            else if (val == "external-event") {
                text = "External Event";

            }




            old[i] = text;


        }
    }
    return old

}


function UpdateItemEdgeDialog(editorUi, valu, targetValue, itemsOperations, edeg)
{





    var eventSataus = "3";

    var div = document.createElement('div');


    var v = valu.replaceAll(" ", "_");

    var mayaDatatran = getValueData(edeg.getId() + "." + v + "__tarnsData.tarns", 1);

    div.appendChild(createItem("Transition Properties", "", "thtitle"));

    /////////////////////////////////////////////////////////////////////
    var divd1 = document.createElement('div');

    divd1.setAttribute('class', '');

    var table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');
    row = document.createElement('tr');

    td = createLabel('Cond:');
    row.appendChild(td);

    td = createIntput(mayaDatatran[1], 'tarns_cond ', 'width:100px');
    row.appendChild(td);

    td = createLabel('Anchor:');
    row.appendChild(td);

    td = createIntput(mayaDatatran[2], 'tarns_anchor ', 'width:100px');
    row.appendChild(td);


    tbody.appendChild(row);

    table.appendChild(tbody);
    divd1.appendChild(table);
    div.appendChild(divd1);
    /////////////////////////////////////////////////////////////////////






    var t1 = mxUtils.button("Use Event From Item Operation", function()
    {

        eventSataus = "1";

        $(".tabs").removeClass("selected");
        $(".t1").addClass("selected");
        $(".alldvs").hide();
        $(".divuse").show();


        $(".getselectData").show();


    })

    t1.setAttribute('class', 'tabs t1 selected');
    div.appendChild(t1);



    var t2 = mxUtils.button("Enter Event", function()
    {

        eventSataus = "2";

        $(".tabs").removeClass("selected");
        $(".t2").addClass("selected");

        $(".alldvs").hide();
        $(".getselectData").hide();
        $(".DontEvent").hide();
        $(".EnterEvent").show();






    })



    t2.setAttribute('class', 'tabs t2');

    div.appendChild(t2);



    var t3 = mxUtils.button("Dont't Use Event", function()
    {
        eventSataus = "3";

        $(".tabs").removeClass("selected");
        $(".t3").addClass("selected");
        $(".alldvs").hide();
        $(".getselectData").hide();
        $(".EnterEvent").hide();
        $(".DontEvent").show();

    })
    t3.setAttribute('class', 'tabs t3');

    div.appendChild(t3);

    divd1 = document.createElement('div');

    divd1.setAttribute('class', 'alldvs divuse');

    if (mayaDatatran[3] != "1") {

        divd1.setAttribute('style', 'Display:none');
    }

    table = document.createElement('table');
    table.style.width = '50%';
    table.style.height = '50%';
    tbody = document.createElement('tbody');
    row = document.createElement('tr');

    row.appendChild(createLabel("Item Operation:"));

    row.appendChild(createSelect($("." + edeg.getId() + "." + v + "__tarnsData.status1.tarns_value").val(), "getselectData  tarns_getselectData", "", itemsOperations.split("__"), updateitemsOperations(itemsOperations.split("__"))));


    tbody.appendChild(row);
    table.appendChild(tbody);
    divd1.appendChild(table);
    divd1.style.width = '100%';
    divd1.style.height = '100%';
    div.appendChild(divd1);




    /////////////////////////////////////////////////////////////////////
    divd1 = document.createElement('div');


    divd1.setAttribute('class', 'alldvs EnterEvent');
    if (mayaDatatran[3] != "2") {

        divd1.setAttribute('style', 'Display:none');
    }


    table = document.createElement('table');
    table.style.width = '50%';
    table.style.height = '50%';
    tbody = document.createElement('tbody');
    row = document.createElement('tr');
    row.appendChild(createLabel("Event:"));
    td = createIntput($("." + edeg.getId() + "." + v + "__tarnsData.status2.tarns_value").val(), 'EnterEvent_event ', 'width:100px');
    row.appendChild(td);


    tbody.appendChild(row);
    table.appendChild(tbody);
    divd1.appendChild(table);

    divd1.style.width = '100%';
    divd1.style.height = '100%';

    div.appendChild(divd1);


    /////////////////////////////////////////////////////////////////////
    divd1 = document.createElement('div');

    divd1.setAttribute('class', 'DontEvent');


    if (mayaDatatran[3] != "3") {

        divd1.setAttribute('style', 'Display:none');
    }

    table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');

    row = document.createElement('tr');

    tbody.appendChild(row);
    table.appendChild(tbody);
    divd1.appendChild(table);

    div.appendChild(divd1);



    /////////////////////////////////////////////////////////////////////


    var v = valu.replaceAll(" ", "_");





    var tvalue = "";


    var myup = mxUtils.button("Update", function() {


        alert(edeg.getId());

        var myadddata = "";

        $("." + edeg.getId() + "." + v + "__tarnsData.tarns").remove();
        $("." + edeg.getId() + "." + v + "__tarnsData.status1.tarns_value").remove();
        $("." + edeg.getId() + "." + v + "__tarnsData.status2.tarns_value").remove();
        $("." + edeg.getId() + "." + v + "__tarnsData.status3.tarns_value").remove();


        v = edeg.getId() + " " + v;


        tvalue = "target__cond__anchor__eventSataus;" + targetValue + "__" + $(".tarns_cond").val() + "__" + $(".tarns_anchor").val() + "__" + eventSataus;
        myadddata += returnInputField(v + "__tarnsData   tarns", tvalue);






        if (eventSataus == "1") {

            /*  tvalue="target__cond__anchor;"+ targetValue+"__"+$(".tarns_cond").val()+"__"+$(".tarns_anchor").val();
             myadddata+=returnInputField (v+"__tarnsData  status1  tar
             ns", tvalue);*/
            if ($(".tarns_getselectData").val() != null) {


                tvalue = $(".tarns_getselectData").val().split("__")[1];

                myadddata += "\n" + returnInputField(v + "__tarnsData status1 tarns_value", tvalue);

            }




        } else if (eventSataus == "2") {



            tvalue = $(".EnterEvent_event").val();
            myadddata += "\n" + returnInputField(v + "__tarnsData  status2  tarns_value", tvalue);

        } else if (eventSataus == "3") {
            /*
             
             tvalue="cond__anchor;"+ $(".tarns_cond").val()+"__"+$(".tarns_anchor").val();
             myadddata+=returnInputField (v+"__tarnsData   tarns", tvalue);*/

            tvalue = "none";
            myadddata += "\n" + returnInputField(v + "__tarnsData  status3 tarns_value", tvalue);





        }




        $(".itmedata").append(myadddata);

        editorUi.hideDialog();

    });

    myup.setAttribute('class', 'myupdate');
    div.appendChild(myup);


    this.container = div;
}

function updateItemDialog(editorUi, valu, classCell, graph)
{



    var div = document.createElement('div');
    div.appendChild(createItem("State Properties", "", "thtitle"));

    var divd1 = document.createElement('div');
    divd1.setAttribute('class', 'divt1');
    var table = document.createElement('table');
    table.style.width = '100%';
    table.style.height = '100%';
    var tbody = document.createElement('tbody');

    row = document.createElement('tr');




    td = document.createElement('td');
    td.style.fontSize = '10pt';
    mxUtils.write(td, 'please enter the name for the ready state:');
    row.appendChild(td);

    td = document.createElement('td');
    td.style.fontSize = '10pt';
    var myinput = document.createElement('input');
    myinput.setAttribute('class', 'nameeventinput');
    myinput.setAttribute('value', classCell.getValue());



    myinput.setAttribute('class', 'nameeventinput');
    myinput.setAttribute('style', 'width:100px;');
    td.appendChild(myinput);
    row.appendChild(td);
    td = document.createElement('td');
    td.style.fontSize = '10pt';

    row.appendChild(td);

    tbody.appendChild(row);

    row = document.createElement('tr');
    td = document.createElement('td');
    td.style.fontSize = '10pt';




    var my = mxUtils.button("Update", function()
    {


        var newdata = $(".nameeventinput").val();



        $(".itmedata .readyitem").val(newdata);



        classCell.setValue(newdata);

        graph.refresh();

        editorUi.hideDialog();

    })


    my.setAttribute('class', 'myupdate');


    td.appendChild(my);



    td.appendChild(myinput);
    row.appendChild(td);

    tbody.appendChild(row);
    table.appendChild(tbody);


    divd1.appendChild(table);




    div.appendChild(divd1);


    this.container = div;

}
